<?php namespace Summer\Maphub\Components;

use Cms\Classes\ComponentBase;
use Summer\Maphub\Models\Settings;


class CompanyMap extends ComponentBase
{
    public $zoomEnable;
    public $zoom;
    public $width;
    public $height;
    public $amap_key;
    public $amap_jscode;
    public $company_longitude;
    public $company_latitude;
    public $company_title;
    public function componentDetails()
    {
        return [
            'name'        => '公司地图',
            'description' => '显示公司地图'
        ];
    }

    public function defineProperties()
    {
        return [
            'zoomEnable' =>[
                'title'         => '可否缩放',
                'description'   => '地图是否可缩放',
                'type'          => 'checkbox',
                'default'       => 1,
            ],
            'zoom' => [
                'title'         => '缩放级别',
                'description'   => '地图显示的缩放级别,可设范围：[2, 30]',
                'type'          => 'string',
                'default'       => 11,
            ],
            'width' => [
                'title'         => '地图宽度',
                'description'   => '地图宽度',
                'type'          => 'string',
                'default'       => '100%',
            ],
            'height' => [
                'title'         => '地图高度',
                'description'   => '地图高度',
                'type'          => 'string',
                'default'       => '500px',
            ]
        ];
    }


    /**
     * prepare Vars function
     * @return [object]
     */
    protected function prepareVars()
    {
        $maphub_settings= Settings::instance();
        $this->amap_key = $this->page['amap_key']=$maphub_settings->amap_key;
        $this->amap_jscode = $this->page['amap_jscode']=$maphub_settings->amap_jscode;
        $this->company_longitude = $this->page['company_longitude']=$maphub_settings->company_longitude;
        $this->company_latitude = $this->page['company_latitude']=$maphub_settings->company_latitude;
        $this->company_title = $this->page['company_title']=$maphub_settings->company_title;

        $this->zoomEnable = $this->page['zoomEnable'] = $this->property('zoomEnable');
        $this->zoom = $this->page['zoom'] = $this->property('zoom');
        $this->width = $this->page['width'] = $this->property('width');
        $this->height = $this->page['height'] = $this->property('height');
    }

    public function onRun(){
        $this->prepareVars();
    }

}
